package Song.Han.day05.demo02;
/*
* 分割字符串方法
* public String[] split (String regex):以参数规则为标志
*
* 注意：
*   split方法的参数其实是一个正则表达式
* */
public class Demo05StringSplit {

    public static void main(String[] args) {
        String str1 = "aaa,bbb,ccc";
        System.out.println(str1);
        String[] array1 = str1.split(",");
        for (Object i:array1) {
            System.out.println(i);
        }
        System.out.println("-----------------");

        String str2 = "aaa bbb ccc";
        System.out.println(str2);
        String[] array2 = str2.split(" ");
        for (Object i :array2) {
            System.out.println(i);
        }
        System.out.println("-----------------");

        //str3分割失败，如果要用"."分割，必须要转义及“\\.”
        String str3 = "aaa.bbb.ccc";
        System.out.println(str3);
        String[] array3 = str3.split("\\.");
        for (Object i :array3) {
            System.out.println(i);
        }

    }
}
